import { _decorator, Component, log, Node, Sprite, SpriteFrame } from 'cc';
import { BundleManager, Bundles } from '../../AshFramework/Managers/BundleManager';
import { Money } from '../Money';
import { GameManager } from '../GameManager';
import { EventManager, MyEvent } from '../../AshFramework/Managers/EventManager';
import { GameUtil } from '../GameUtil';
const { ccclass, property } = _decorator;

@ccclass('UIButton')
export class UIButton extends Component {

    isClick: boolean = true;//能否点击

    private _sprite: Sprite = null;
    private _normalSF: SpriteFrame = null;
    private _cancelSF: SpriteFrame = null;
    private _MoneyTs: Money = null;
    protected onLoad(): void {
        this._sprite = this.getComponent(Sprite);
        this._MoneyTs = this.getComponent(Money);

        this._normalSF = BundleManager.AssetMap.get("按钮") as SpriteFrame;
        this._cancelSF = BundleManager.AssetMap.get("灰色按钮") as SpriteFrame;
    }

    setBtnStyle() {
        if (GameManager.Instance.userData.gold >= this._MoneyTs.money) {
            this._sprite.spriteFrame = this._normalSF;
            this.isClick = true;
        } else {
            this._sprite.spriteFrame = this._cancelSF;
            this.isClick = false;
        }
    }
    protected onEnable(): void {
        EventManager.on(MyEvent.BUTTON_STYLE, this.setBtnStyle, this);
    }


    protected onDisable(): void {
        EventManager.off(MyEvent.BUTTON_STYLE, this.setBtnStyle, this);
    }

}


